package com.iweb.servlet;

import com.iweb.pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/selectList")
public class UserServlet  extends HttpServlet {


    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 模拟数据
        List<User> users = new ArrayList<>();
        users.add(new User(1,"jack",20));
        users.add(new User(2,"tom",20));
        users.add(new User(3,"小黑",20));
        users.add(new User(4,"小明",20));
        // HttpServletRequest 保存数据
        req.setAttribute("users",users);
        // 视图转发
        req.getRequestDispatcher("/main.jsp").forward(req,resp);
    }
}
